//----------------------------------
//--------Airboat GunSWEP--------------
//-----------Made by Foss----
//----------------------------------
//---Part of the SMOD Weapons Pack--
//----------------------------------

//if on server
if SERVER then

	//add the file
	AddCSLuaFile("shared.lua");

	//set the hold type
	SWEP.HoldType			= "ar2";

end

//if on client
if CLIENT then

	//set some stuff
	SWEP.PrintName			= "Airboat Gun";
	SWEP.Author				= "Foss";
	SWEP.Slot				= 3;
	SWEP.SlotPos			= 3;
	SWEP.Purpose			= "Who took this off the airboat..?";
	SWEP.Instructions		= "Left Click: Fire";

	//set the category
	SWEP.Category			= "SMOD";
	
	//selection icon
	SWEP.WepSelectIcon = surface.GetTextureID("weapons/absmodicon");
	
	--Killicon
	if(file.Exists("../materials/weapons/absmod_killicon.vmt")) then

		killicon.Add("weapon_abgun","weapons/absmod_killicon",Color(255,255,255));

	end 

end

//is it spawnable?
SWEP.Spawnable				= true;
SWEP.AdminSpawnable			= false;

//models
SWEP.ViewModel				= "models/weapons/v_Irifle.mdl";
SWEP.WorldModel				= "models/weapons/w_Irifle.mdl";

//more stuff
SWEP.Weight					= 25;
SWEP.AutoSwitchTo			= false;
SWEP.AutoSwitchFrom			= false;

SWEP.ThinkDelay				= 0
SWEP.ReloadDelay			= 0
SWEP.FireSound				= nil

//primary settings
SWEP.Primary =
{
	ClipSize				= 50,
	DefaultClip				= -1,
	Automatic				= true,
	Ammo					= "ar2"
}

//secondary settings
SWEP.Secondary =
{
	ClipSize				= -1,
	DefaultClip				= -1,
	Automatic				= false,
	Ammo					= "none"
}

//on initialize
function SWEP:Initialize()

	//if on server
	if SERVER then

		//set the hold type
		self:SetWeaponHoldType(self.HoldType);

	end
	
	self.FireSound = CreateSound(self.Weapon, "Airboat.FireGunLoop")
	
	self.Weapon:SetClip1(50)

end

function SWEP:Precache()

	util.PrecacheSound("Airboat.FireGunLoop")

end

function SWEP:Think()

	//if we don't have any keys pressed
	if !self.Owner:KeyDown(IN_ATTACK) then

		//if the delay is off
		if CurTime() > self.ThinkDelay then

			//give ammo
			self.Weapon:SetClip1(math.Clamp(self.Weapon:Clip1() + 1,0,50))

			//set the delay
			self.ThinkDelay = CurTime() + 0.08;

		end

	end

	//when pressed fire
	if self.Owner:KeyPressed(IN_ATTACK) && self.Weapon:Clip1() > 1 && CurTime() > self.ReloadDelay then

		//play sound
		self.FireSound:Play();

	end

	//when released fire
	if self.Owner:KeyReleased(IN_ATTACK) and CurTime() > self.ReloadDelay then

		//stop sound
		self.FireSound:Stop();
		
		//reload animation
		self.Weapon:SendWeaponAnim(ACT_VM_RELOAD)
		self.Weapon:SetNextPrimaryFire(CurTime() + 1.2)
		
		//set the delay
		self.ReloadDelay = CurTime() + 1.2

	end

	//when out of ammo
	if self.Weapon:Clip1() < 1 then

		//stop sound
		self.FireSound:Stop();

	end

end

//when reloading
function SWEP:Reload()

	//stop
	return false;

end

//when holstering
function SWEP:Holster()

	//sound off
	self.FireSound:Stop();

	//return
	return true;

end

//when restoring
function SWEP:OnRestore()

	//sound off
	self.FireSound:Stop();

end

function SWEP:PrimaryAttack()

	if self:CanPrimaryAttack() then
		self:FireBullet(Vector(0.044, 0.044, 0.044))
		self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
		self.Weapon:SetNextPrimaryFire(CurTime() + 0.025)
	end
	

end

function SWEP:FireBullet(Spread)

	if self:CanPrimaryAttack() then
		//create a bullet
		local Bullet = {};

		//set it up
		Bullet.Src = self.Owner:GetShootPos();
		Bullet.Attacker = self.Owner;
		Bullet.Dir = self.Owner:GetAimVector();
		Bullet.Spread = Spread;
		Bullet.Num = 1;
		Bullet.Damage = 8;
		Bullet.Force = 8;
		Bullet.Tracer = 1;
		Bullet.TracerName = "AirboatGunTracer";
		Bullet.Callback = function (attacker, tr, dmginfo)
							local fx = EffectData()
							fx:SetOrigin(tr.HitPos)
							fx:SetNormal(tr.HitNormal)
							util.Effect("AirboatGunImpact", fx)
						end
						
		//fire it
		self.Weapon:FireBullets(Bullet);
		self:ShootEffects();
		
		//take off some ammo
		self:TakePrimaryAmmo(1);
	end

end
